package com.newbingo.service;

import java.util.Date;

import com.newbingo.dao.imple.IMemberDao;
import com.newbingo.dto.MemberDto;
import com.newbingo.dto.imple.IBettingItemDto;
import com.newbingo.dto.imple.IMemberDto;
import com.newbingo.entity.Member;
import com.newbingo.service.imple.IMemberService;
import com.newbingo.util.Pager;
import com.newbingo.util.TimeUtil;

/**
 * 会员业务Service
 * 
 */
public class MemberService implements IMemberService {
	private IMemberDao memberDao = null;
	private IMemberDto memberDto = null;
	private IBettingItemDto bettingItemDto = null;

	
   /*
    * 查询会员投注记录
    * */
	public Pager findByMemberId(int start,int limit,int memberId,String gameName,Date startTime,Date endTime){
		return bettingItemDto.findByMemberId(start, limit, memberId, gameName, startTime, endTime);
	}

	/*
	 * 分页查询，返回DTO对象
	 */
	public Pager findMembersByPage(int start, int limit, String uname,
			Integer agentId) {
		return memberDto.findByPage(start, limit, uname, agentId);
	}
 
	/*
	 * 会员登录
	 */
	public MemberDto findByLogin(String uname,String upwd){
		return memberDto.findByLogin(uname, upwd);
	}
	
	/*
	 * 根据会员ID查询出信息,返回MemberDto
	 */
	public MemberDto findById(Integer uno){
		return memberDto.findById(uno);
	}

	/*
	 * 根据会员ID查询 返回Member
	 */
	public Member findByMemberId(Integer uno){
		return memberDao.findById(uno);
	}
	
	/*	 
	 * 创建新会员 
	 */
	public void createNewMember(Member member) {
		memberDao.save(member);
	}

	/*
	 * 修改会员信息
	 */
	public void updateMember(Member member) {
		Member instance=memberDao.findById(member.getUno());
		//将前台的对象数据赋值给持久层进行保存
		instance.setTrueName(member.getTrueName());
		instance.getContactInfo().setEmail(member.getContactInfo().getEmail());
		instance.getContactInfo().setTel(member.getContactInfo().getTel());
		instance.setMaxBet(member.getMaxBet());
		instance.setMinBet(member.getMinBet());
		if (member.getLastLoginIp()!=null) {
			instance.setLastLoginIp(member.getLastLoginIp());
		}else {
			instance.setLastLoginIp(instance.getLastLoginIp());
		}
		if (member.getLastLogTime()!=null) {
			instance.setLastLogTime(member.getLastLogTime());
		}else {
			instance.setLastLogTime(instance.getLastLogTime());
		}
		if (member.getLoginAmount()!=null) {
			instance.setLoginAmount(member.getLoginAmount());
		}else {
			instance.setLoginAmount(instance.getLoginAmount());
		}
		memberDao.merger(instance);
	}

	/*
	 * 修改会员状态
	 */
	public void updateMemberStatus(Member member) {
		Member instance = memberDao.findById(member.getUno());
		instance.setStatus(member.getStatus());
		memberDao.merger(instance);
	}

	/*
	 * 删除会员
	 */
	public void deleteMember(Member member) {
		memberDao.delete(member);
	}
	
	/*
	 * 根据代理商和时间段，如本周等 进行分页查询会员的报表
	 */
	public Pager findMemberReportByPager(int start,int limit,Integer agentId,Integer dateNum){
		return memberDao.findMemberReportByPager(start, limit, agentId, TimeUtil.getTimePeriod(dateNum));
	}
	

	public IMemberDao getMemberDao() {
		return memberDao;
	}

	public void setMemberDao(IMemberDao memberDao) {
		this.memberDao = memberDao;
	}

	public IMemberDto getMemberDto() {
		return memberDto;
	}

	public void setMemberDto(IMemberDto memberDto) {
		this.memberDto = memberDto;
	}

	public IBettingItemDto getBettingItemDto() {
		return bettingItemDto;
	}

	public void setBettingItemDto(IBettingItemDto bettingItemDto) {
		this.bettingItemDto = bettingItemDto;
	}



}
